<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .dd{
            width: 800px;
            height: 40px;
            background-color: red;
            margin:  0 auto;
        }
        .nav{
            width: 800px;
            height: 50px;
            background-color: yellow;
            margin:  0 auto;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }
        .nav input{
            width: 400px;
            height: 50px;
            border: 0;
            border-radius: 20px;
        }

        .zz{
            width: 800px;
            height: 2000px;
            background-color: pink;
            margin:  0 auto;
        }
    </style>
</head>

<body>
<header class="dd"></header>
<div class="nav" id="ll">
    <input type="text">
    <span>百度搜索</span>
</div>
<main class="zz">

</main>
</body>

</html>
<script>
    window.onscroll=function(){
        if(scrollY>40){
            ll.style.cssText=`
            position:sticky;
            top:0;
            background-color:green;
            `
        }else{
            ll.style.cssText=`
            background-color:yellow;
            `
        }
    }
</script>